#!/usr/bin/env ruby -w
#--
# Project:      pkgman
# File:         test/make_pkgs.rb
# Revision:     $Id$
# Home:         http://code.google.com/p/pkgman/
# Author:       Derek Olsen <someword at gmail dot com>
# Copyright:    (c) 2007 by Derek Olsen
# License:      GNU General Public License v2 
#++

# This script is used to create solaris packages out of the contents
# of the contents of the pkg_prototypes directory.

require 'zlib'

# Define where we have the package prototypes
proto_dir = "pkg_prototypes"
pkg_dir = "pkgs"

# Create the pkgs directory if it doesnt exist
Dir.mkdir(pkg_dir) unless File.directory?(pkg_dir)

# Iterate through all the prototypes and create pkgs
Dir.foreach(proto_dir) do |d|
   next unless File.exists?("#{proto_dir}/#{d}/prototype")
     # Let's find out what the pkg name should be.  
     pkg_name = File.readlines("#{proto_dir}/#{d}/pkginfo")[0].split(/=/)[1]
      
     # Make the actual pkg
     system("/usr/bin/pkgmk -o -b #{proto_dir}/#{d} -f #{proto_dir}/#{d}/prototype 2>/dev/null")

     # Translate the pkg into datastream
     system("/usr/bin/pkgtrans -o -s /var/spool/pkg #{File.expand_path(pkg_dir)}/#{d} #{pkg_name} 2>/dev/null")

     system("/usr/bin/rm -rf /var/spool/pkg/ZZZpkgman-upgrade*")
end  

# Gzip the test gzip pkg
system("/usr/bin/gzip -f pkgs/ZZZpkgman-gzip-test")
